import pandas as pd
import os
import sys
import time
import numpy as np
import datetime
from clickhouse_driver import Client

#导入数据库
def batch_process(path):
    client = Client(host="192.168.50.40", user="default", password="9defbcg", port="9090", database="ods")
    print("start batch process hot data...")
    #读取csv数据，必须指定类型，否则会推测为int，导致异常
    df = pd.read_csv(path, dtype={'采集日期': str, '股票代码': str, '人气排行': int, '变化':int}
                     , encoding="UTF-8", index_col=False)  # 取消索引列，否则错位

    print(df.head())

    client.execute('INSERT INTO ods_stock_hot_df VALUES', df.values.tolist())
    #关闭连接 TODO
    print("batch process stock hot data finished!")

# 必须有main方法，调度才能执行
def main():
    print("etl_hot start....")
    path = sys.argv[1]
    #批量导入到CK
    batch_process(path)
    # batch_process("G:\\task-pipeline\\df_day\\all_day_20230817.csv")


if __name__ == '__main__':
    main()



